package com.example.saiweisi.service.impl.sysTemAdminService;
import cn.hutool.core.date.DateUtil;
import com.example.saiweisi.controller.request.NewsRequest;
import com.example.saiweisi.mapper.systemAdminMapper.NewsMapper;
import com.example.saiweisi.model.News;
import com.example.saiweisi.service.interf.INewsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class NewsService implements INewsService {
    @Autowired
    NewsMapper newsMapper;
    @Override
    public PageInfo<News> page(NewsRequest newsRequest) {
        PageHelper.startPage(newsRequest.getPageNum(), newsRequest.getPageSize());
        List<News> userList = newsMapper.newslistByCondition(newsRequest);
        return new PageInfo<>(userList);
    }

    @Override
    public void addnews(News news) {
        news.setCreattime(DateUtil.now());
        newsMapper.addnews(news);
    }

    @Override
    public void deletenews(Long newsId) {
        newsMapper.deletenews(newsId);
    }

    @Override
    public News getById(Long newsId) {
        return newsMapper.getById(newsId);
    }

    @Override
    public void updatenews(News news) {
        newsMapper.updatenews(news);
    }

    @Override
    public void deletesnews(List<Long> newsIds) {
        for (Long a:newsIds
        ) {
            newsMapper.deletenews(a);
        }
    }

    @Override
    public List<News> getall() {

        return newsMapper.getall();
    }
}
